package com.lzy.mall.ware.service.impl;

import com.lzy.mall.common.enume.OrderStatusEnum;
import com.lzy.mall.ware.entity.WmsWareOrderTaskDetail;
import com.lzy.mall.ware.dao.WmsWareOrderTaskDetailDao;
import com.lzy.mall.ware.service.WmsWareOrderTaskDetailService;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/**
 * 库存工作单(WmsWareOrderTaskDetail)表服务实现类
 *
 * @author lzy
 * @since 2021-08-24 19:01:56
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class WmsWareOrderTaskDetailServiceImpl implements WmsWareOrderTaskDetailService {
    private final WmsWareOrderTaskDetailDao wmsWareOrderTaskDetailDao;

    @Override
    public void save(WmsWareOrderTaskDetail detailEntity) {
        wmsWareOrderTaskDetailDao.insertTemplate(detailEntity,true);
    }

    @Override
    public WmsWareOrderTaskDetail getById(Long id) {
        return wmsWareOrderTaskDetailDao.single(id);
    }

    @Override
    public void updateById(WmsWareOrderTaskDetail taskDetail) {
        wmsWareOrderTaskDetailDao.updateTemplateById(taskDetail);
    }

    @Override
    public WmsWareOrderTaskDetail getLockById(Long detailId) {
        return wmsWareOrderTaskDetailDao.createLambdaQuery()
                .andEq(WmsWareOrderTaskDetail::getId,detailId)
                .andEq(WmsWareOrderTaskDetail::getLockStatus, OrderStatusEnum.LOCK_STATUS_LOCK.getCode())
                .single();
    }

    @Override
    public List<WmsWareOrderTaskDetail> getByTaskId(Long id) {
        return wmsWareOrderTaskDetailDao.createLambdaQuery()
                .andEq(WmsWareOrderTaskDetail::getTaskId,id)
                .select();
    }
}
